package com.example.demo.controller;


import com.example.demo.result.RestResponse;
import com.example.demo.result.ResultGenerator;
import com.example.demo.service.ScanUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 扫脸库用户信息表 前端控制器
 * </p>
 *
 * @author lst
 * @since 2019-12-18
 */
@RestController
@RequestMapping("/scan/face")
@Api(value = "ScanUserController",tags = "扫脸用户录入")
public class ScanUserController {

    @Autowired
    private ScanUserService scanUserService;

    /**
     * 人脸注册
     * @param file 文件
     * @return RestResponse
     * @author lst
     * @since 2019-12-18
     */
    @PostMapping(value = "/register", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "人脸注册", notes = "人脸注册", code = 200, produces = "application/json")
    public RestResponse resisterFace(@RequestParam(name = "file", required = true) MultipartFile file) {
        return ResultGenerator.genSuccessResult(scanUserService.resisterFace(file));
    }

    /**
     * 人脸对比
     * @param file 文件
     * @param userId 用户ID
     * @return RestResponse
     * @author lst
     * @since 2019-12-18
     */
    @PostMapping(value = "/compare", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "人脸对比", notes = "人脸对比", code = 200, produces = "application/json")
    public RestResponse compareFace(@RequestParam(name = "file", required = true) MultipartFile file,
                                    @RequestParam(name = "userId", required = true) String userId) {
        return ResultGenerator.genSuccessResult(scanUserService.compareFace(file, userId));
    }

}
